//
//  RMMTaoCanConfirmTableViewCell.m
//  Romomo
//
//  Created by puman on 2016/12/29.
//  Copyright © 2016年 mazegong. All rights reserved.
//

#import "RMMTaoCanConfirmTableViewCell.h"

@implementation RMMTaoCanConfirmTableViewCell
{
    UIImageView *_imageV;
    UILabel *_titleLabel;
    UILabel *_priceLabel;
    UIView *_view;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        _imageV = [[UIImageView alloc] initWithFrame:CGRectMake(15, 10, 40, 40)];
        [self.contentView addSubview:_imageV];
        
        _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(_imageV.right + kRow, _imageV.top, 150, _imageV.height)];
        _titleLabel.textColor = COLORFROMCODE(0x000000, 1);
        _titleLabel.font = kFont(14);
        _titleLabel.numberOfLines = 0;
        [self.contentView addSubview:_titleLabel];
        
        _priceLabel = [[UILabel alloc] initWithFrame:CGRectMake(_titleLabel.right, _imageV.top + 10, 95, 20)];
        _priceLabel.textColor = COLORFROMCODE(0x000000, 1);
        _priceLabel.textAlignment = NSTextAlignmentRight;
        _priceLabel.font = kFont(14);
        [self.contentView addSubview:_priceLabel];
        
        _view = [[UIView alloc] initWithFrame:CGRectMake(kScreenWideth - 83, _imageV.bottom + kRow, 68, 24)];
        _view.layer.masksToBounds = YES;
        _view.layer.cornerRadius = 12;
        _view.backgroundColor = COLORFROMCODE(0xEEEEEE, 1);
        [self.contentView addSubview:_view];
        
        _countLabel = [[UILabel alloc] initWithFrame:_view.bounds];
        _countLabel.font = kFont(13);
        _countLabel.textAlignment = NSTextAlignmentCenter;
        _countLabel.textColor = COLORFROMCODE(0x303137, 1);
        [_view addSubview:_countLabel];
        
        _subBut = [UIButton buttonWithType:(UIButtonTypeCustom)];
        _subBut.frame = CGRectMake(_view.left - kRow, _view.top - kRow, 44, 44);
        [_subBut setImage:[UIImage imageNamed:@"un-subtract@3x"] forState:(UIControlStateNormal)];
        [self.contentView addSubview:_subBut];
        
        _addBut = [UIButton buttonWithType:(UIButtonTypeCustom)];
        _addBut.frame = CGRectMake(_subBut.right, _subBut.top, 44, 44);
        [_addBut setImage:[UIImage imageNamed:@"add@3x"] forState:(UIControlStateNormal)];
        [self.contentView addSubview:_addBut];
        for (int i = 0; i < 20; i++) {
            UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(_imageV.left, _imageV.bottom + kRow + 20 * i, kScreenWideth - 93 - 15, 20)];
            label.textColor = COLORFROMCODE(0x9B9B9B, 1);
            label.font = kFont(12);
            label.hidden = YES;
            label.tag = 100 + i;
            [self.contentView addSubview:label];
        }
    }
    return self;
}
- (void)setDic:(NSDictionary *)dic{
    [_imageV sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",kBaseImageUrl,[RMMFileManager retrunObjWith:dic[@"PROD_BOM"][@"IMAGEURL"]]]] placeholderImage:[UIImage imageNamed:@"加载中@3x"]];
    _titleLabel.text = dic[@"PROD_BOM"][@"NAME"];
    _priceLabel.text = [NSString stringWithFormat:@"¥%@",dic[@"PROD_BOM"][@"PRICE"]];
    CGFloat width = [UILabel backHeightWithString:_priceLabel.text CGFloatCount:20 metho:WIDTH font:14] + 5;
    _priceLabel.frame = CGRectMake(kScreenWideth - width - 15, _imageV.top + 10, width, 20);
    _titleLabel.frame = CGRectMake(_imageV.right + kRow, _imageV.top, kScreenWideth - _imageV.right - 10 - width - 15, _imageV.height);
    NSArray *array = dic[@"PROD_SERVICES"];
    for (int i = 0; i < array.count; i++) {
        UILabel *label = [self viewWithTag:100 + i];
        label.hidden = NO;
        NSDictionary *subDic = array[i];
        label.text = [NSString stringWithFormat:@"%@ x%@",subDic[@"SERVICE_NAME"],subDic[@"SERVICE_QTY"]];
        [self changeLabelTextColorOneWithLabel:label forRange:NSMakeRange(label.text.length - 3, 3) byColor:COLORFROMCODE(0xB5B5B5, 1)];
    }
    NSInteger count = array.count;
    if (count > 1) {
        _view.frame = CGRectMake(kScreenWideth - 83, _imageV.bottom + kRow + (20 * count - 24) / 2.0, 68, 24);
        _subBut.frame = CGRectMake(_view.left - kRow, _view.top - kRow, 44, 44);
        _addBut.frame = CGRectMake(_subBut.right, _subBut.top, 44, 44);
    }
}
- (void)setPayDic:(NSDictionary *)payDic{
//    [_imageV sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",kBaseImageUrl,[RMMFileManager retrunObjWith:payDic[@"PROD_BOM"][@"IMAGEURL"]]]] placeholderImage:[UIImage imageNamed:@"加载中@3x"]];
//    _titleLabel.text = payDic[@"PROD_BOM"][@"NAME"];
//    _priceLabel.text = [NSString stringWithFormat:@"¥%@",payDic[@"PROD_BOM"][@"PRICE"]];
//    _priceLabel.textColor = COLORFROMCODE(0x9B9B9B, 1);
//    NSArray *array = payDic[@"PROD_SERVICES"];
//    for (int i = 0; i < array.count; i++) {
//        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(_imageV.left, _imageV.bottom + kRow + 20 * i, 150, 20)];
//        label.textColor = COLORFROMCODE(0x9B9B9B, 1);
//        label.font = kFont(12);
//        [self.contentView addSubview:label];
//        NSDictionary *subDic = array[i];
//        label.text = [NSString stringWithFormat:@"%@ x%@",subDic[@"SERVICE_NAME"],subDic[@"SERVICE_QTY"]];
//        [self changeLabelTextColorOneWithLabel:label forRange:NSMakeRange(label.text.length - 3, 3) byColor:COLORFROMCODE(0xB5B5B5, 1)];
//    }

}
- (void)changeLabelTextColorOneWithLabel:(UILabel *)label forRange:(NSRange)range byColor:(UIColor *)color{
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:label.text];
    [attributedString addAttribute:NSForegroundColorAttributeName value:color range:range];
    [attributedString addAttribute:NSFontAttributeName value:kFont(12) range:range];
    [label setAttributedText:attributedString];
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
